<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8"/>
    <title>添加</title>
    <link href="__STATIC__/component/pear/css/pear.css" rel="stylesheet"/>
</head>
<body class="childrenBody {:dialog_css()}">

<form class="layui-form" action="{:url('add')}" method="post" lay-filter="authtree-submit-form">

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-item-required">角色</label>
        <div class="layui-input-block">
            <input type="text" name="title" lay-verify="required" lay-reqtext="请输入角色名称" placeholder="请输入角色名称" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label layui-form-item-required">描述</label>
        <div class="layui-input-block">
            <input type="text" name="memo" lay-verify="required" lay-reqtext="请输入角色描述" placeholder="请输入角色描述" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label layui-form-item-required">菜单显示</label>
        <div class="layui-input-block">
            <div id="LAY-auth-tree-index"></div>
        </div>
    </div>

    <div class="layui-form-item layer-footer">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" lay-filter="save">
                <i class="layui-icon layui-icon-ok"></i>
                添加
            </button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>

</form>
<script src="__STATIC__/component/layui/layui.js"></script>
<script src="__STATIC__/component/pear/pear.js?v={:site_ver()}"></script>
<script>
    layui.use(['form', 'jquery', 'aphp', 'authtree'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let aphp = layui.aphp;
        let authTree = layui.authtree;

        $.getJSON("{:url('api_auth_menu')}?selected=2", function (res) {
            authTree.render('#LAY-auth-tree-index', res.data, {
                inputname: 'tree_ids[]',
                layfilter: 'lay-check-auth',
                childKey: 'children',
                nameKey: 'title',
                valueKey: 'id',
                theme: 'auth-skin-default',
                themePath: '__STATIC__/component/pear/module/authtree/tree_themes/',
                autowidth: true,
                formFilter: 'authtree-submit-form'
            });
        });

        form.on('submit(save)', function (data) {
            let tree_ids = authTree.getChecked('#LAY-auth-tree-index');
            data.field.auth_menu = (tree_ids.length > 0) ? tree_ids.join(',') : '';
            aphp.request.postForm(data, 0, function () {
                parent.layer.close(parent.layer.getFrameIndex(window.name));
                parent.layui.table.reload('currentTable');
            });
            return false;
        });

    });
</script>
</body>
</html>